package com.rpc.demo.provider;

import com.rpc.demo.provider.rpc.server.RpcServer;
import com.rpc.demo.common.config.RegisterCenter;
import com.rpc.demo.provider.service.BookServiceImpl;
import com.rpc.demo.provider.service.IBookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: ZhaoJie
 * @Date: 2022/4/6
 * @Description:
 * @Modify: ===================================================
 * Modifier        Modifytime        Description
 * ===================================================
 */

public class Provider2 {
    private static Logger logger = LoggerFactory.getLogger(Provider2.class);
    private static Map<String, Class> serviceMap = new HashMap<>();
    private static String tcpHost = "127.0.0.2:12001";

    static {
        /**
         * 模拟service配置处理逻辑
         * <dubbo:service interface="com.client.service.IBookService" ref="bookService" />
         * <bean id="bookService" class="com.provider.service.BookServiceImpl" />
         */
        serviceMap.put(IBookService.class.getName(), BookServiceImpl.class);
    }

    public static void main(String[] args) {
        //将服务和服务提供者URL注册到注册中心
        RegisterCenter registerCenter = new RegisterCenter();
        for (Map.Entry<String, Class> entry : serviceMap.entrySet()) {
            registerCenter.register(entry.getKey(), tcpHost);
        }

        //监听Consumer的远程调用(为了简化代码, 这里使用TCP代替Netty)
        RpcServer rpcServer = new RpcServer(serviceMap);
        rpcServer.start(12001);

    }

}
